#pragma once


#include <iostream>
#include <fstream>
#include <unordered_map>
#include <string>
#include "log.hpp"

const std::string dictname = "./dict.txt";
const std::string sep = ":";


bool split(const std::string& line, std::string& p1, std::string& p2)
{
    size_t pos = line.find(":");
    if(pos == std::string::npos)
    {
        return false;
    }
    p1 = line.substr(0, pos);
    p2 = line.substr(pos + 1);

    return true;
}

class init
{
public:
    init()
    {
        std::ifstream in(dictname);
        if(!in.is_open())
        {
            lg(Fatal, "ifstream open %s error", dictname.c_str());
            exit(1);
        }

        std::string line;
        while(std::getline(in, line))
        {
            std::string part1, part2;
            if(split(line, part1, part2))
            {
                _dict.insert({ part1, part2 });
            }
        }
        in.close();
    }

    std::string translation(const std::string& key)
    {
        if(_dict.count(key) == 0)
            return "UnKonw";
        
        return _dict[key];
    }

private:
    std::unordered_map<std::string, std::string> _dict;
};